class Solution
{
public:
    long long minimumSteps(string s)
    {
        int oneCount = 0;
        for (auto c : s)
        {
            if (c == '1')
            {
                ++oneCount;
            }
        }
        if (oneCount == 0 || oneCount == s.size())
        {
            return 0;
        }
        int front = s.size() - oneCount;
        int back = s.size() - 1;
        long long ans = 0;
        while (true)
        {
            while (front >= 0 && s[front] == '0')
            {
                --front;
            }
            if (front < 0)
            {
                break;
            }
            while (back >= s.size() - oneCount && s[back] == '1')
            {
                --back;
            }
            if (back < s.size() - oneCount)
            {
                break;
            }
            swap(s[front], s[back]);
            ans += back - front;
        }
        return ans;
    }
};